/**
 * 
 */
package fr.fermeManager.library.model.beans;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Mo
 *
 */
public class Ferme {
	
	private boolean actif = true;
	private boolean principale = false;
	
	private String description;
	private String libelle;
	
	private int id;
	
	private List<Transaction> transactions =  new ArrayList<Transaction>();
	
	private List<TypeTransaction> typesTransactions =  new ArrayList<TypeTransaction>();
	
	public void ajouterTransaction(Transaction nouveauTransac) {
		this.getTransactions().add(nouveauTransac);
	}

	public void ajouterTypeTransaction(TypeTransaction typeTransactionSelectionnee) {
		this.getTypesTransactions().add(typeTransactionSelectionnee);
	}
	
	public void modifierTransaction(Transaction transacParam) {
		for (Transaction transacTmp : this.transactions) {
			if(transacParam.getId() == transacTmp.getId()){
				
				transacTmp.setActif(transacParam.isActif());
				transacTmp.setDescritption(transacParam.getDescritption());
				transacTmp.setLibelle(transacParam.getLibelle());
				transacTmp.setMontant(transacParam.getMontant());
				transacTmp.setTypeTransaction(transacParam.getTypeTransaction());
				
				return;
			}
		}
	}

	public void modifierTypeTransaction(TypeTransaction typeTransactionSelectionnee) {
		for (TypeTransaction typeTransacTmp : this.getTypesTransactions()) {
			if(typeTransactionSelectionnee.getId() == typeTransacTmp.getId()){
				
				typeTransacTmp.setActif(typeTransactionSelectionnee.isActif());
				typeTransacTmp.setDescritption(typeTransactionSelectionnee.getDescritption());
				typeTransacTmp.setEstSortie(typeTransactionSelectionnee.isEstSortie());
				typeTransacTmp.setIdParent(typeTransactionSelectionnee.getIdParent());
				typeTransacTmp.setLevel(typeTransactionSelectionnee.getLevel());
				typeTransacTmp.setLibelle(typeTransactionSelectionnee.getLibelle());
				
				return;
			}
		}
	}
	
	public void supprimerTransaction(Transaction transacParam) {
		this.getTransactions().remove(transacParam);
	}

	public void supprimerTypeTransaction(TypeTransaction typeTransactionSelectionnee) {
		this.typesTransactions.remove(typeTransactionSelectionnee);
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @return the libelle
	 */
	public String getLibelle() {
		return libelle;
	}

	/**
	 * @return the transactions
	 */
	public List<Transaction> getTransactions() {
		return transactions;
	}

	/**
	 * @return the typesTransactions
	 */
	public List<TypeTransaction> getTypesTransactions() {
		return typesTransactions;
	}

	/**
	 * @return the actif
	 */
	public boolean isActif() {
		return actif;
	}

	/**
	 * @return the principale
	 */
	public boolean isPrincipale() {
		return principale;
	}

	/**
	 * @param actif the actif to set
	 */
	public void setActif(boolean actif) {
		this.actif = actif;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * @param libelle the libelle to set
	 */
	public void setLibelle(String libelleParam) {
		this.libelle = libelleParam;
	}
	
	/**
	 * @param principale the principale to set
	 */
	public void setPrincipale(boolean principale) {
		this.principale = principale;
	}
	
	/**
	 * @param transactions the transactions to set
	 */
	public void setTransactions(List<Transaction> transactions) {
		this.transactions = transactions;
	}

	/**
	 * @param typesTransactions the typesTransactions to set
	 */
	public void setTypesTransactions(List<TypeTransaction> typesTransactions) {
		this.typesTransactions = typesTransactions;
	}
	
	@Override
	public String toString() {
		return libelle;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Ferme other = (Ferme) obj;
		if (id != other.id)
			return false;
		return true;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}
}